<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function twoSum(nums,target){
            let map = new Map();
            for(let i = 0;i<nums.length;i++){
                let n = nums[i];
                let n2 = target - n;
                if(map.has(n2)){
                    return [map.get(n2),i];
                }else{
                    map.set(n,i);
                }
            }
        }
        console.log(twoSum([2,7,11,15],9));
    </script>
</body>
</html>